package com.htdst.mockserver.util;

import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

public class Config
{
	private static Logger		logger		= Logger.getLogger(Config.class);
	private static Properties	properties	= new Properties();

	static
	{
		try
		{
			properties.load(Config.class.getClassLoader().getResourceAsStream(
					"config.properties"));
		}
		catch (IOException e)
		{
			logger.error("Fail to load config.properties", e);
		}
	}

	public static int getPort()
	{
		Object port = properties.get("port");
		if (port == null)
		{
			logger.warn("port is not configured, using default port: "
					+ Constants.PORT);
			return Constants.PORT;
		}
		return Integer.valueOf((String) port);
	}

	public static String getCharsetEncoding()
	{
		Object charsetEncoding = properties.get("charsetEncoding");
		if (charsetEncoding == null)
		{
			logger.warn("charsetEncoding is not configured, using default charsetEncoding: "
					+ Constants.DEFAULT_CHARSET);
			return Constants.DEFAULT_CHARSET;
		}
		return (String) charsetEncoding;
	}

	public static int getThreadPoolSize()
	{
		Object threadPoolSize = properties.get("threadPoolSize");
		if (threadPoolSize == null)
		{
			logger.warn("threadPoolSize is not configured, using default threadPoolSize: "
					+ Constants.POOL_SIZE);
			return Constants.POOL_SIZE;
		}
		return Integer.valueOf((String) threadPoolSize);
	}

}
